package jfuzzyprincepless.zarchive.algorithm.structure.forcnstr;

public class ForLoopExecutor<E> {
	private final Iterable<E> iterable;

	private E current = null;
	private boolean isRun = false;

	public ForLoopExecutor(
		Iterable<E> iterable
	) {
		this.iterable = iterable;
	}

	public E getCurrentElem() {
		if (!isRun) {
			throw new IllegalStateException(
				"Not running at the momnet"
			);
		}
		return current;
	}

	public void execute(Runnable eachIterExecute) {
		isRun = true;
		for (E item : iterable) {
			current = item;
			eachIterExecute.run();
		}
		isRun = false;
	}
}
